package com.nullbrain.sp;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SPCommandHandler implements CommandExecutor {

    public SlashPlayed plugin;

    /**
     * @param plugin
     */
    public SPCommandHandler(SlashPlayed plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

        // Check to see if user used no args:

        if (args.length == 0) {
            // send message to sender explaining not enough args as well as usage
            sender.sendMessage(this.plugin.config.getString("sp.error.tooFewParam"));
            sender.sendMessage("Usage: /sp current|total");
            return true;
        }

        if (args.length > 1) {
            // send message to sender explaining there were too many args as well as usage
            sender.sendMessage(this.plugin.config.getString("sp.error.tooManyParam"));
            sender.sendMessage("Usage: /sp current|total");
            return true;
        }

        if (args[0].equalsIgnoreCase("current")) {

            return true;
        }

        if (args[0].equalsIgnoreCase("total")) {
            sender.sendMessage("You have played for " + GetTimePlayed((Player) sender));
            return true;
        }

        return false;
    }

    /**
     * @param p
     * @return time played formatted
     */
    public String GetTimePlayed(Player p) {

        return new StringBuilder().append("00 Days ").append("00 Hours ").append("00 minutes ").append("00 seconds ")
                .toString();
    }
}
